﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.LongER.Framework.Utils;
using Com.LongER.Business.ZHM002;
using Com.LongER.Business.ZHM002.ZHM002DSTableAdapters;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using Com.LongER.Framework.Utils.LogUtils;


namespace Com.LongER.Business.ZHM002
{
    public class CZHM002 : ABussinessBase
    {
        private Log log = Log.GetInstance();

        /// <summary>
        /// 获取用户详细信息的值
        /// </summary>
        /// <returns></returns>
        public ZHM002DS.M_USERDETAILDataTable GetMUSerDetail(String strUserId)
        {
            String connectionString = ConnectionStringUtil.GetConnectionString();
            M_USERDETAILTableAdapter ta = new M_USERDETAILTableAdapter(connectionString);

            ZHM002DS.M_USERDETAILDataTable tb = ta.GetData(strUserId);
            ta.Connection.Close();
            return tb;
        }

        /// <summary>
        /// 获取员工详细信息的值
        /// </summary>
        /// <returns></returns>
        public ZHM002DS.M_STAFFDETAILDataTable GetMStaffDetail(string strStaffId)
        {
            String connectionString = ConnectionStringUtil.GetConnectionString();
            M_STAFFDETAILTableAdapter ta = new M_STAFFDETAILTableAdapter(connectionString);

            ZHM002DS.M_STAFFDETAILDataTable tb = ta.GetData(strStaffId);
            ta.Connection.Close();
            return tb;
        }


        /// <summary>
        /// 追加用户详细信息的值
        /// </summary>
        /// <returns></returns>
        public Boolean InsertMUSer(String strNewUserId, String strNewStaffId, String strNewUserName, 
                                       String strNewPWD, String strNewPWD_YOUXIAO_ADMMDD)
        {
            String connectionString = ConnectionStringUtil.GetConnectionString();
            M_USERDETAILTableAdapter ta = new M_USERDETAILTableAdapter(connectionString);

            int result = ta.InsertM_USER(strNewUserId, strNewStaffId, strNewUserName,
                                                strNewPWD, strNewPWD_YOUXIAO_ADMMDD);
            ta.Connection.Close();
            if (result > 0) return true;

            return false;
        }

        /// <summary>
        /// 更新用户表和员工表
        /// </summary>
        /// <param name="strUserId"></param>
        /// <param name="strPassword"></param>
        /// <returns></returns>
        public Boolean UpdateMUserMStaff(String strUserId, String strNewStaffId, String strNewUserName, 
                                       String strNewPWD, String strNewPWD_YOUXIAO_ADMMDD,
                                       String strNewSHO , String strNewBumen, String strNewZHIWEI, 
                                       String strNewMobile1,String strNewMobile2,String strNewMailAdd)
        {
            String connectionString = ConnectionStringUtil.GetConnectionString();
            M_USERDETAILTableAdapter ta = new M_USERDETAILTableAdapter(connectionString);

            int result = ta.UpdateM_USER(strNewStaffId, strNewPWD, strNewPWD_YOUXIAO_ADMMDD, strNewUserName, strUserId);
            if (result <= 0) return false;

            //result = ta.UpdateM_STAFF(strNewUserName, strNewSHO, strNewBumen, strNewZHIWEI,
            //                          strNewMobile1, strNewMobile2, strNewMailAdd,
            //                          strUserId);
            ta.Connection.Close();

            if (result > 0) return true;

            return false;
        }

        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <returns></returns>
        public Boolean DeleteMUSer(String strUserId)
        {
            String connectionString = ConnectionStringUtil.GetConnectionString();
            M_USERDETAILTableAdapter ta = new M_USERDETAILTableAdapter(connectionString);

            int result = ta.DeleteM_USER(strUserId);
            ta.Connection.Close();
            if (result > 0) return true;

            return false;
        }


    }
}
